import jsonp from 'fetch-jsonp'


const parseParams = function(params){
    let paramsStr = "?";
    for (const key in params) {
        paramsStr += `${key}=${params[key]}&`
    }
    return paramsStr.replace(/&$/,"")
}

export default {
    request(url,params={}){
        let paramsStr = parseParams(params)
        let requestPromise = jsonp(url+paramsStr)
                .then((response)=>{
                    return response.json();
                })
                .catch((error)=>{
                    console.log(error)
                    return false;
                })
        return  requestPromise     
    }
}